package org.rcloud.io.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import org.rcloud.io.Utils.PageVo;
import org.rcloud.io.Utils.ResultVo;
import org.rcloud.io.mapper.DituMapper;
import org.rcloud.io.model.Ditu;
import org.rcloud.io.service.DituService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2019/1/26.
 */
@Service(value = "dituService")
public class DituServiceImpl implements DituService {

    @Autowired
    private DituMapper dituMapper;

    @Override
    public ResultVo saveMap(Ditu ditu) {

        if (ditu.equals("") || ditu == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                int i = dituMapper.insertSelective(ditu);
                return ResultVo.setOK(i);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public ResultVo findMapId(Integer id) {

        if (id.equals("") || id == null) {
            return ResultVo.setError("传入数据为空");
        } else {
            try {
                Ditu ditu = dituMapper.selectByPrimaryKey(id);
                return ResultVo.setOK(ditu);
            } catch (Exception e) {
                e.printStackTrace();
                return ResultVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public PageVo<Ditu> findMapNum(String num) {

        if (num.equals("") || num == null) {
            return PageVo.setError("传入数据为空");
        } else {
            try {
                List<Ditu> list = dituMapper.selectByNum(num);
                return PageVo.setOk(list);
            } catch (Exception e) {
                e.printStackTrace();
                return PageVo.setError(e.getMessage());
            }
        }

    }

    @Override
    public PageVo<Ditu> findMapTyep() {

        try {
            List<Ditu> list = dituMapper.select();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }

    }

    @Override
    public PageVo<Ditu> findMapAll() {

        try {
            List<Ditu> list = dituMapper.selectAll();
            return PageVo.setOk(list);
        } catch (Exception e) {
            e.printStackTrace();
            return PageVo.setError(e.getMessage());
        }
    }

    @Override
    public ResultVo selectByPrimaryKey(Ditu id) {
        try {
            Ditu mapvs = dituMapper.selectBydd(id);
            return ResultVo.setOK(mapvs);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVo.setError(e.getMessage());
        }

    }

    @Override
    public PageInfo<Ditu> mapByOther(JSONObject record) {//只是JSONObject的别名，也可以写sss
        List<Ditu> mapvsList = dituMapper.mapByOther(record);
        PageInfo<Ditu> pageInfo = new PageInfo<>(mapvsList);
        return pageInfo;
    }

}
